﻿using Microsoft.AspNetCore.Razor.TagHelpers;
using System;

namespace ReaWTM.LayuiHelper
{
	[HtmlTargetElement("wt:qrcode", TagStructure = TagStructure.WithoutEndTag)]
	public class QRCode : TagHelper
	{
		public string Id { get; set; } = $"qrcode_{Guid.NewGuid():N}";
		public int Height { get; set; } = 96;

		public int Width { get; set; } = 96;

		public string Text { get; set; }

		public override void Process(TagHelperContext context, TagHelperOutput output)
		{
			output.TagName = "div";
			output.TagMode = TagMode.StartTagAndEndTag;
			output.Attributes.Add("id", Id);
			output.PreContent.AppendHtml($@"<script>wtm.qrcode_Render('#{Id}','{Text}',{Width},{Height})</script>");
		}
	}
}
